import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/views/layout'

const constantRoutes = [{
		path: '/login',
		name: 'login',
		component: () => import('@/views/login/index'),
		hidden: true,
	},
	{
		path: '/layout',
		name: 'layout',
		component: () => import('@/views/layout/index'),
		hidden: true,
	},
	{
		path: '/',
		component: Layout,
		redirect: '/dashboard',
		children: [{
		  path: 'dashboard',
		  name: 'Home',
		  component: () => import('@/views/home/index'),
		  meta: { title: '首页', icon: 'dashboard' }
		}]
	},
	{
		path: '/excel',
		component: Layout,
		redirect: '/excel/index',
		children: [{
			path: 'index',
			name: 'Excel',
			component: () => import('@/views/read-excel-file/index'),
			meta: {
				title: 'Excel-File',
				icon: 'el-icon-monitor',
			}
		}]
	},
	{
		path: '/video',
		component: Layout,
		redirect: '/video/index',
		children: [{
			path: 'index',
			name: 'Video',
			component: () => import('@/views/video/flv.vue'),
			meta: {
				title: '播放器',
				icon: 'el-icon-monitor',
			}
		}]
	},
	{
		path: '/example',
		component: Layout,
		redirect: '/example/design',
		name: 'Example',
		meta: { title: 'Example', icon: 'el-icon-s-help' },
		children: [{
			path: 'design',
			name: 'Design',
			component: () => import('@/views/design/index'),
			meta: {
				title: '测试',
				icon: 'el-icon-monitor',
			}
		}]
	},
	{
		path: '/upload',
		component: Layout,
		redirect: '/upload/index',
		children: [{
				path: 'index',
				name: 'upload',
				component: () => import('@/views/upload/index'),
				meta: {
					title: '上传',
					icon: 'el-icon-monitor',
				}
			},
			// {
			// 	path: 'section',
			// 	name: 'section',
			// 	component: () => import('@/views/upload/section'),
			// 	meta: {
			// 		title: '切片',
			// 		icon: 'el-icon-monitor',
			// 	}
			// }
		]
	}
]


const createRouter = () => new Router({
	// mode: 'history', // require service support
	scrollBehavior: () => ({
		y: 0
	}),
	routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
	const newRouter = createRouter()
	router.matcher = newRouter.matcher // reset router
}

export default router
